<script setup>
import { ref, onMounted } from 'vue';

import OrderItem from '@/components/order/orderItem.vue'

import { getOrderListService } from '@/api/order';


const orderList = ref([])
const loading = ref(false)
const page = ref(1)
const pageSize = ref(3)
const pageSizes = [3, 4, 5, 6, 100]
const total = ref(0)

const getOrderList = async () => {
    loading.value = true
    try {

        const res = await getOrderListService(page.value, pageSize.value)
        orderList.value = res.data.list
        total.value = res.data.total
        console.log(res.data);
    } finally {
        loading.value = false
    }
}

//分页逻辑
const handlePagination = () => {
    getOrderList()
}


onMounted(() => {
    getOrderList()
})

</script>
<template>
    <div class="order-container" v-loading="loading">
        <OrderItem v-for="item in orderList" :key="item.id" :order="item"></OrderItem>

        <div class="pagination" v-if="orderList.length">
            <Pagination :hidden="orderList.length" v-mode:page="page" v-model:pageSize="pageSize"
                :page_Sizes="pageSizes" :total="total" @pagination="handlePagination"></Pagination>
        </div>

        <el-empty v-else class="empty" description="暂无数据" />
    </div>

</template>
<style scoped lang='scss'>
.order-container {
    width: 100%;
    height: 100%;
    min-height: 500px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #f2f2f2;
    padding: 10px;
    box-sizing: border-box;
    overflow: auto;
}

.pagination {
    width: 75rem;
    margin-left: auto;
}
</style>